#include <iostream>
#include <sstream>
#include <vector>
#include <fstream>
#include <string>
using namespace std;
class Record{
public:
    Record(string word,int frequency)
        :_word(word)
         ,_frequency(frequency)
    {

    }

    friend
        class Dictionary;
private:
    string _word;
    int _frequency;
};

class Dictionary{
public:
    Dictionary(int capacity){
        _dict.reserve(capacity);
    }

    void read(const string & filename){
        ifstream ifs(filename);
        if(!ifs.good()){
            cerr << "eorror" << endl;
            return;
        }
        string line;
        while(getline(ifs,line)){
            istringstream iss(line);
            string word;
            while(iss >> word){
                int i = 0;
                for(i = 0;i < _dict.size();i++ ){
                    if(_dict[i]._word == word){
                        _dict[i]._frequency++;
                        break;
                    }
                }        
                if( i ==_dict.size()){
                    _dict.push_back(Record(word,1));
                } 
            }
        }
        ifs.close();
    }

    void store(const string & filename){
        ofstream ofs(filename);
        for(int i = 0;i<_dict.size();i++){
            ofs << _dict[i]._word << ":"  << _dict[i]._frequency << endl;
        }
        ofs.close();
    }
private:
    vector<Record> _dict;
};

void test(){ 
    Dictionary dict(10000);
    dict.read("The_Holy_Bible.txt");
    dict.store("bible.txt");
}

int main()
{
    test();
    return 0;
}

